package com.cheng.common.results;

import com.cheng.common.utils.CodeUtil;

/**
 * @author: ChengJW
 * @date: 2021/11/1 22:39
 * @version: 1.0
 * @description: 统一响应消息
 */
public class DataRslt {

    /** 状态*/
    private String code;

    /** 消息*/
    private String msg;

    /** 数据*/
    private Object data;

    public DataRslt(String code, String msg){
        this.code = code;
        this.msg = msg;
        this.data = null;
    }

    public DataRslt(String code, String msg, Object data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
    * @author: ChengJW
    * @params: [data]
    * @return: com.cheng.common.results.DataRlst
    * @date: 2021/11/2
    * @description: 统一成功返回消息
    */
    public static DataRslt success(Object data){
       return new DataRslt(CodeUtil.SUCCESS_CODE,CodeUtil.SUCCESS_MSG,data);
    }

   /**
   * @author: ChengJW
   * @params: []
   * @return: com.cheng.common.results.DataRlst
   * @date: 2021/11/2
   * @description: 统一失败返回消息
   */
    public static DataRslt failure(Object data){
        return new DataRslt(CodeUtil.FAILURE_CODE,CodeUtil.FAILURE_MSG,data);
    }

    /**
    * @author: ChengJW
    * @params: []
    * @return: com.cheng.common.results.DataRlst
    * @date: 2021/11/2
    * @description: 统一异常返回消息
     */
    public static DataRslt exception(){
        return  new DataRslt(CodeUtil.EXCEPTION_CODE,CodeUtil.EXCEPTION_MSG);
    }

    /**
     * @author: ChengJW
     * @params: []
     * @return: com.cheng.common.results.DataRlst
     * @date: 2021/11/2
     * @description: 统一异常返回消息
     */
    public static DataRslt exception(Object data){
        return  new DataRslt(CodeUtil.EXCEPTION_CODE,CodeUtil.EXCEPTION_MSG,data);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
